package com.boang.local;

/*
  @author: 13813
  @date: 2024/11/27 16:27
*/
public class ThreadLocalDemo {
    public static ThreadLocal<Integer> local = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    Integer i1 = local.get();
                    local.set(i1 + 1);
                    System.out.println(Thread.currentThread().getName() + ":" + local.get());
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    Integer i1 = local.get();
                    local.set(i1 + 1);
                    System.out.println(Thread.currentThread().getName() + ":" + local.get());
                }
            }
        }).start();


    }
}
